<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        敏感词替换
    </div>
    <div class = "word">,,bad,idjsdbadwordagjiojabadgw;ojg</div>
</body>
<script>
    var badwords = ["bad","badword"];

    var wordDom = document.querySelector(".word");
    var text = wordDom.innerText;

    console.log(text.includes("bad"));
    for(var i = 0; i< badwords.length; i++) {
        while (text.indexOf(badwords[i])!= -1){
            text = text.replace(badwords[i],"***");
            wordDom.innerText = text;
        }
    }
</script>
</html>